1 /* 2 3 Boost Software License - Version 1.0 - August 17th, 2003 4 5 Permission is hereby granted, free of charge, to any person or organization 6 obtaining a copy of the software and accompanying documentation covered by 7 this license ( the "Software" ) to use, reproduce, display, distribute, 8 execute, and transmit the Software, and to prepare derivative works of the 9 Software, and to permit third-parties to whom the Software is furnished to 10 do so, all subject to the following: 11 12 The copyright notices in the Software and this entire statement, including 13 the above license grant, this restriction and the following disclaimer, 14 must be included in all copies of the Software, in whole or in part, and 15 all derivative works of the Software, unless such copies or derivative 16 works are solely in the form of machine-executable object code generated by 17 a source language processor. 18 19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 23 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 DEALINGS IN THE SOFTWARE. 26 27 */ 28 module derelict.nanomsg.nanomsg; 29 30 public { 31 import derelict.nanomsg.types; 32 import derelict.nanomsg.functions; 33 } 34 35 private { 36 import derelict.util.loader; 37 import derelict.util.system; 38 39 static if( Derelict_OS_Windows ) 40 enum libNames = "nanomsg.dll"; 41 else 42 static assert( 0, "Need to implement Nanomsg2 libNames for this operating system." ); 43 } 44 45 /* 46 This function is not part of the public interface, but Nanomsg expects it to be called before any subsystems have been intiailized. 47 Normally, this happens via linking with libNanomsgmain, but since that doesn't happen when using Derelict, then the loader must 48 load this function and call it before the load method returns. Otherwise, bad things can happen. 49 */ 50 private extern( C ) nothrow alias da_Nanomsg_SetMainReady = void function(); 51 52 class DerelictNanomsgLoader : SharedLibLoader { 53 public this() { 54 super( libNames ); 55 } 56 57 protected override void loadSymbols() { 58 bindFunc(cast(void**)&nn_errno, "nn_errno"); 59 bindFunc(cast(void**)&nn_strerror, "nn_strerror"); 60 bindFunc(cast(void**)&nn_symbol, "nn_symbol"); 61 bindFunc(cast(void**)&nn_symbol_info, "nn_symbol_info"); 62 bindFunc(cast(void**)&nn_term, "nn_term"); 63 bindFunc(cast(void**)&nn_allocmsg, "nn_allocmsg"); 64 bindFunc(cast(void**)&nn_reallocmsg, "nn_reallocmsg"); 65 bindFunc(cast(void**)&nn_freemsg, "nn_freemsg"); 66 67 version(none) { 68 //... 69 } 70 71 bindFunc(cast(void**)&nn_socket, "nn_socket"); 72 bindFunc(cast(void**)&nn_close, "nn_close"); 73 bindFunc(cast(void**)&nn_setsockopt, "nn_setsockopt"); 74 bindFunc(cast(void**)&nn_getsockopt, "nn_getsockopt"); 75 bindFunc(cast(void**)&nn_bind, "nn_bind"); 76 bindFunc(cast(void**)&nn_connect, "nn_connect"); 77 bindFunc(cast(void**)&nn_shutdown, "nn_shutdown"); 78 bindFunc(cast(void**)&nn_send, "nn_send"); 79 bindFunc(cast(void**)&nn_recv, "nn_recv"); 80 bindFunc(cast(void**)&nn_sendmsg, "nn_sendmsg"); 81 bindFunc(cast(void**)&nn_recvmsg, "nn_recvmsg"); 82 bindFunc(cast(void**)&nn_poll, "nn_poll"); 83 bindFunc(cast(void**)&nn_device, "nn_device"); 84 } 85 } 86 87 __gshared DerelictNanomsgLoader DerelictNanomsg; 88 89 shared static this() { 90 DerelictNanomsg = new DerelictNanomsgLoader(); 91 } 92 93 shared static ~this() 94 { 95 DerelictNanomsg.unload(); 96 }